﻿using System;

class ChangeTextToUppercase
{
    static void Main()
    {
        string someText = "<upcase>Begin </upcase>We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.<upcase> end</upcase>";
        string firstTag = "<upcase>";
        string secondTag = "</upcase>";
        string newText = "";

        for (int index = 0; index < someText.Length;)
        {
            int firstIndex = someText.IndexOf(firstTag, index);
            int secondIndex = someText.IndexOf(secondTag, index);

            if (firstIndex != -1)
            {
                // Copying the text up to "<upcase>"
                int startPosition = index; ;
                int strLength = firstIndex - index;
                newText += someText.Substring(startPosition, strLength);

                // Copying the text between "<upcase>" and "</upcase>" and applying ToUpper() method
                startPosition = firstIndex + firstTag.Length;
                strLength = secondIndex - startPosition;
                newText += someText.Substring(startPosition, strLength).ToUpper();

                // Moving the index after "</upcase>"
                index = secondIndex + secondTag.Length;
            }
            else
            {
                // No more tags are found and 
                // we copy all the text to the end
                newText += someText.Substring(index);
                break;
            }
        }

        Console.WriteLine(newText);
    }
}
